<template>
	<view >
		<view class="bj"></view>
		<view class="bj2"></view>
		<view class="banner">
			<swiper
			class="swiper" 
			autoplay="ture" 
			:interval="interval" 
			:duration="duration" 
			style="height: 100%;" 
			:circular="true">
				
				<swiper-item v-for="(item,index) in banner" :key="index">
					<image :src="item"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="content">
			<view class="left">
				<image src="../../static/man.png"></image>
				<view class="list-btn" @click="onPut(1)">放入一张男生纸条</view>
				<view class="list-btn" @click="onextract(1)">抽取一张男生纸条</view>
			</view>
			<view class="right">
				<image src="../../static/woman.png" mode=""></image>
				<view class="list-btn" @click="onPut(0)">放入一张女生纸条</view>
				<view class="list-btn" @click="onextract(0)">抽取一张女生纸条</view>
			</view>
		</view>
		<u-popup v-model="show" close-icon-pos="top-left" mode="bottom" border-radius="14" :closeable="true">
				<view class="pop-view" >
					<view class="pop-title">{{type==0?'放入一张女生纸条':'放入一张男生纸条'}}</view>
					<view class="pop-text" style="padding-top: 0;">
						<view class="pop-addr">
							<view @click="addrshow=true"><u-icon name="map-fill" style="margin-right: 10rpx;"></u-icon>{{selector[addrSelect]}}</view>
						</view>
						<view class="pop-textarea">
							<textarea value="" placeholder="您的交友简介 (介绍自己或对另一半的期待)..." placeholder-style="#aeaeae" v-model="inputvalue"/>
						</view>
						<view class="pop-img">
							<view v-for="(item,index) in image" :key="index" >
								<image @click="pictureView(index,image)" :src="item"></image>
								<text class="del" @click="ondel(index)">X</text>
							</view>
							<view>
								<image @click="myUpload" src="../../static/add.png"></image>
							</view>
						</view>
						<view class="pop-bottom">
							<view class="pop-bottom-left">我的微信号<u-icon name="arrow-right" color="#b3b3b3"></u-icon></view>
							<view class="pop-bottom-right"><input type="text" v-model="wxcode" placeholder="只有抽到你的人才能看到"></view>
						</view>
						<view class="pop-tips-text">
							纸条的生命<view>被抽一次后自动销毁<u-icon name="arrow-right" color="#acacac" size="28"></u-icon></view>
						</view>
					</view>
					<view class="pop-tips" v-if="type==0">
						1元/1次
					</view>
					<view class="pop-tips" v-if="type==1">
						1元/1次
					</view>
					<view class="pop-btn" >
						确认放入
					</view>
				</view>
			</u-popup>
			<u-popup v-model="extract" close-icon-pos="top-left" mode="bottom" border-radius="14" :closeable="true">
				<view class="pop-view">
					<view class="pop-title">{{type==0?'抽取一张女生纸条':'抽取一张男生纸条'}}</view>
					
					<view class="pop-extract-img">
						<image v-if="type==0" src="../../static/cq.png"></image>
						<image v-else src="../../static/cq2.png"></image>
					</view>
					<view class="pop-addr2">
						<view class="pop-addr2-list">
							仅抽取{{selector[addrSelect]}}<view> <switch :checked="checked" @change="switch1Change" /></u-switch></view>
						</view>
					</view>
					<view class="pop-tips">
						1元/张
					</view>
					<view class="pop-btn" >
						确认抽取
					</view>
				</view>
			</u-popup>
			<u-picker @confirm="onconfirm" mode="selector" v-model="addrshow"  :default-selector="[addrSelect]" :range="selector"></u-picker>
			<view class="login-btn" v-if="onloginstate">
				拆个盲盒，每天惊喜不断!<view>微信一键登录</view>
			</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				onloginstate:true,
				interval: 5000, //自动切换时间间隔
				duration: 500, //滑动动画时长
				banner:['../../static/banner1.jpg','../../static/banner2.jpg'],
				show:false,
				extract:false,
				type:0,
				addrshow:false,
				selector: ['全国', '北京市', '天津市','河北省','山西省','内蒙古自治区','辽宁省','吉林省','黑龙江省','上海市','江苏省','浙江省','安徽省','福建省','江西省','山东省','河南省','湖北省','湖南省','广东省','广西壮族自治区','海南省','重庆市','四川省','贵州省','云南省','西藏自治区','陕西省','甘肃省','青海省','宁夏回族自治区','新疆维吾尔自治区','台湾省','香港特别行政区','澳门特别行政区'],
				addrSelect:0,
				checked:false,
				inputvalue:'' ,// 放入内容
				image:[], //图片内容
				wxcode:'',
			} 
		},
		watch: {
				
		},
		methods:{
			bc_code(image){
				console.log(123456)
				let that = this;
				//console.log('保存二维码')
				uni.downloadFile({           //获得二维码的临时地址
					url:image,
					success:(res)=>{
						//console.log('获取url',res)
						if(res.statusCode == 200){
							uni.saveImageToPhotosAlbum({
								filePath:res.tempFilePath,//传入临时地址
								success() {
									uni.showToast({
										title: '保存成功',
										icon: 'none'
									});
								},
								fail() {
									uni.showToast({
										title: '保存失败',
										icon: 'none'
									});
								}
							})
						}
					},
					fail:(err)=>{
						console.log(err)
					}
				})
			},
			ondel(index){
				this.image.splice(index, 1)
				console.log('删除')
			}, 
			// 预览图片
			pictureView(index,imags){
				let imgs = imags.map( item =>{
				//只返回图片路径
					return item
				})
				// console.log(imgs);
				//调用预览图片的方法
				uni.previewImage({
					urls:imgs,
					current:index
				})
			},
			//上传返回图片
		  	myUpload(index) {
				uni.showLoading();
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						console.log(tempFilePaths[0],'-----47----')
						uni.uploadFile({
							url: '', // 上传图片路径
							filePath: tempFilePaths[0],
							name: 'file',
							success: (res) => {
								setTimeout(function () {
									uni.hideLoading();
								}, 200);
								
							},
							fail: (res) => {
								setTimeout(function () {
									uni.hideLoading();
								}, 200);
							}
						});
					}
				});
			},
			switch1Change(e){
				console.log(e)
				this.checked = e.target.value
				if(e.target.value==true){
					this.addrshow = true
				}
			},
			onextract(type){
				this.type = type
				this.extract=true
			},
			onPut(type){
				this.type = type
				this.show=true
			},
			onconfirm(e){
				console.log(e)
				this.addrSelect = e[0]
			},
		},
		onLoad() {
			
		},
	}
</script>
<style>
	page{
		width: 100%;
		padding: 0 20rpx;
		box-sizing: border-box;
	}
</style>
<style scoped lang="less">
	.bj{
		width: 100vw;
		height: 100vh;
		background: linear-gradient(to right, #f4cccc, #cfe2f3); /* 标准的语法 */
		position: fixed;
		top: 0;
		left: 0;
		z-index: -2; 
	}
	.bj2{
		width: 100vw;
		height: 100vh;
		background-image: url(../../static/bj.png) ;
		position: fixed;
		top: 0;
		left: 0;
		z-index: -1;
	}
	.box{
		width: 100%;
		padding: 0 20rpx;
		box-sizing: border-box;
		margin-top: 36rpx;
	}
	.banner{
		width: 100%;
		height: 300rpx;
		margin-top: 50rpx;
		image{
			width: 100%;
			height: 100%;
			border-radius: 10rpx;
			margin-left: 5rpx;
			border-radius: 20rpx;
		}
	}
	.content{
		width: 100%;
		height: 587rpx;
		margin-top: 60rpx;
		display: flex;
		flex-flow:row wrap;
		justify-content: space-between;
		
	}
	.content>view{
		width: 346rpx;
		height: 587rpx;
		position: relative;
		padding: 352rpx 22rpx 0 22rpx;
		box-sizing: border-box;
		image{
			width: 100%;
			height: 100%;
			position: absolute;
			top: 0;
			left: 0;
			border-radius: 20rpx;
			z-index: -1;
		}
	}
	.list-btn{
		width: 100%;
		height: 98rpx;
		border-radius: 20rpx;
		background-color: #000;
		font-size: 28rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #fff;
		margin-bottom: 20rpx;
		box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.12);
	}
	.pop-view{
		width: 100%;
		padding: 47rpx 49rpx 66rpx 49rpx;
		box-sizing: border-box;
	}
	.pop-title{
		width: 100%;
		height: 36rpx;
		line-height: 36rpx;
		text-align: center;
		font-weight: bold;
	}
	.pop-text{
		width: 100%;
		// height: 440rpx;
		border: 4rpx solid #000000;
		border-radius: 16rpx;
		margin-top: 55rpx;
		padding: 24rpx 19rpx 0 19rpx;
		box-sizing: border-box;
		.pop-textarea{
			width: 100%;
			height: 168rpx;
			textarea{
				width: 100%;
				height: 168rpx;
				font-size: 28rpx;
			}
		}
		
	}
	.pop-img{
		width: 100%;
		display: flex;
		flex-flow:row wrap;
		justify-content: space-between;
		border-bottom: 1rpx solid #e7e7e7;
		view{
			width: 120rpx;
			height: 120rpx;
			position: relative;
			image{
				width: 120rpx;
				height: 120rpx;
				border-radius: 5rpx;
				margin-bottom: 13rpx;
			}
		}
	}
	.pop-img:after {
		content: "";
		width: 120rpx;
	}
	.del{
		position: absolute;
		top: 0;
		right: 0;
		font-size: 25rpx;
		height: 35rpx;
		line-height: 35rpx;
		text-align: center;
		width: 35rpx;
		background: rgba(0,0,0,0.5);
		border-radius: 5rpx;
		color: #fff;
		padding: 5rpx;
		}
	.pop-bottom{
		width: 100%;
		display: flex;
		flex-flow:row wrap;
		justify-content: space-between;
	}
	.pop-bottom-left{
		width: 210rpx;
		height: 110rpx;
		line-height: 110rpx;
		font-size: 28rpx;
		display: flex;
		// justify-content: center;
		align-items: center;
		border-right: 1rpx solid #e7e7e7;
	}
	.pop-bottom-right{
		width: 398rpx;
		height: 110rpx;
		line-height: 110rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
		color: #aaaaaa;
		input{
			width: 100%;
			height: 110rpx;
			line-height: 110rpx;
			padding-left: 20rpx;
			box-sizing:border-box;
		}
	}
	.pop-tips{
		width: 100%;
		height: 45rpx;
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: bold;
		text-align: center;
		margin: 35rpx 0 32rpx 0;
	}
	.pop-btn{
		width: 100%;
		height: 99rpx;
		border-radius: 24rpx;
		background: #000000;
		line-height: 99rpx;
		text-align: center;
		color: #fff;
		font-size: 26rpx;
	}
	.pop-extract-img{
		width: 100%;
		height: 300rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 34rpx;
		image{
			width: 240rpx;
			height: 300rpx;
		}
	}
	.pop-info{
		margin: 46rpx 0 80rpx 0;
	}
	.bottom-text{
		width: 100%;
		height: 30rpx;
		line-height: 30rpx;
		padding: 0 190rpx;
		box-sizing: border-box;
		font-size: 25rpx;
		margin-top: 57rpx;
		display: flex;
		flex-flow:row wrap;
		justify-content: space-between;
		font-weight: bold;
	}
	.pop-h2{
		width: 100%;
		height: 32rpx;
		line-height: 32rpx;
		font-size: 20rpx;
		color: #747474;
		text-align: center;
	}
	.pop-image{
		width: 100%;
		height: 377rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 44rpx;
		image{
			width: 377rpx;
			height: 377rpx;
		}
	}
	.pop-tips-text{
		width: 100%;
		height: 110rpx;
		line-height: 110rpx;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		border-top: 1rpx solid #e7e7e7;
		view{
			height: 100%;
			margin-left: auto;
			
		}
	}
	.pop-addr{
		width: 100%;
		height: 90rpx;
		display: flex;
		align-items: center;
		border-bottom: 1rpx solid #e7e7e7;
		margin-bottom: 24rpx;
		view{
			padding: 0 15rpx;
			height: 50rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 23rpx;
			color: #fff;
			background-color: #000;
			border-radius: 10rpx;
		}
	}
	.pop-addr2{
		width: 100%;
		background-color: #f4f4f4;
		border-radius: 15rpx;
		margin: 30rpx 0;
	}
	.pop-addr2>view:nth-last-child(1){
		border-bottom: none;
	}
	.pop-addr2-list{
		width: 100%;
		height: 110rpx;
		line-height: 110rpx;
		display: flex;
		align-items: center;
		font-size: 27rpx;
		padding: 0 34rpx;
		border-bottom: 1rpx solid #e7e7e7;
		view{
			height: 100%;
			margin-left: auto;
			display: flex;
			align-items: center;
		}
	}
	.login-btn{
		width: 100%;
		height: 100rpx;
		position: fixed;
		left: 0;
		bottom: 20rpx;
		background-color: #fff;
		border-radius: 40rpx;
		display: flex;
		flex-flow:row wrap;
		justify-content: space-between;
		align-items: center;
		color: #303133;
		padding: 0 20rpx 0 30rpx;
		box-sizing: border-box;
		view{
			width: 320rpx;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			font-size: 30rpx;
			background-color: #303133;
			border-radius: 40rpx;
			color: #fff;
		}
	}
</style>
